package com.learn.twoday;

import org.apache.log4j.Logger;

import java.util.concurrent.TimeUnit;

/**
 * @author ln
 * @Description: ${todo}
 * @date 2020/12/9
 */
public class JoinTest {

    private static final Logger logger=Logger.getLogger(JoinTest.class);

    static int r1=0;
    static int r2=0;

    public static void main(String[] args) {
        test2();
    }

    private static void test2() {
        Thread t1=new Thread(
                ()->{
                    try {
                        TimeUnit.SECONDS.sleep(1);
                        r1=10;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
        ,"t1");

        Thread t2=new Thread(
                ()->{
                    try {
                        TimeUnit.SECONDS.sleep(2);
                        r2=20;
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
        ,"t2");

        t1.start();
        t2.start();
        logger.debug("t1 join begin");
        try {
            t1.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.debug("t1 join end");
        try {
            t2.join();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        logger.debug("t1 join end");



    }

}
